package com.droidnova.android.games.vortex;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.util.Log;

public class lines 
{

	// Our vertex buffer.
	private FloatBuffer _vertexBuffer;

	// Our index buffer.
	private ShortBuffer _indexBuffer;
	
	
	float[] _pvertices1;
	
	ByteBuffer vbb;
	
	ByteBuffer ibb;


	private short[] _indices = {0,1,1,2,2,3,3,0,4,5,5,6,6,7,7,4,3,7,2,6,0,4,1,5};  // The order we like to connect them.

	float g=0.0f;
	private float a1,b1,c1;
	public float getA1() {
		return a1;
	}

	public void setA1(float a2) {
		a1 = a2;
	}

	public float getB1() {
		return b1;
	}

	public void setB1(float b2) {
		b1 = b2;
	}

	public float getC1() {
		return c1;
	}

	public void setC1(float c2) {
		c1 = c2;
	}
	public float[] get_pvertices1() {
		return _pvertices1;
	}

	public void set_pvertices1(float[] _pvertices1) {
		this._pvertices1 = _pvertices1;
	}

	public lines(float a,float b , float c)
	{

		Log.w("MyClassName", "This is a warning");
		setA1(a);
		setB1(b);
		setC1(c);
		//a1 =a;
		//b1=b;
		//c1=c;

		Log.v("X value", "FOUND x value -> " + a1 + b1 + c1);
		
		
		/*
		float[] _pvertices = { 
				g, g, g,      //front bottom left  v1
				a1, g, g,     //front  bottom right  v2
				a1, b1, g,     //front  top   right   v3
				g, b1, g,     //front  top  left     v4 
				g, g, c1,    // back bottom left   v5
				a1, g, c1,    // back bottom right v6
				a1, b1, c1,    // back top right  v7
				g, b1, c1,    // back top left   v8


		};
		*/
		
		set_pvertices1(setvertex(getA1(),getB1(),getC1()));

		// a float is 4 bytes, therefore we multiply the number if 
		// vertices with 4.
		/*ByteBuffer vbb = ByteBuffer.allocateDirect(_pvertices.length * 4);
		vbb.order(ByteOrder.nativeOrder());
		_vertexBuffer = vbb.asFloatBuffer();
		_vertexBuffer.put(_pvertices);
		_vertexBuffer.position(0);*/

		// short is 2 bytes, therefore we multiply the number if 
		// vertices with 2.
		/*ByteBuffer ibb = ByteBuffer.allocateDirect(_indices.length * 2);
		ibb.order(ByteOrder.nativeOrder());
		_indexBuffer = ibb.asShortBuffer();
		_indexBuffer.put(_indices);
		_indexBuffer.position(0);*/
	
	}
	
	public float[] setvertex(float a1, float b1 , float c1)
	{
		
		float[] _pvertices = { 
				g, g, g, a1,g, g,   // bottom line 1			
				a1,g, g, a1,b1,g,	// bottom line 2
				a1,b1,g, g, b1,g,	// bottom line 3
				g, b1,g, g, g, g,	// bottom line 4
				
				g, g, c1, a1,g, c1,   // top line 1			
				a1,g, c1, a1,b1,c1,	// top line 2
				a1,b1,c1, g, b1,c1,	// top line 3
				g, b1,c1, g, g, c1,	// top line 4

				g, g, g, g, g, c1,   //side line 1			
				a1,g, g, a1,g, c1,	// side line 2
				a1,b1,g, a1,b1,c1,	// side line 3
				g, b1,g, g, b1,c1,	// side line 4
		};
		return _pvertices;
	}
	
	public float[] convertStringArraytoFloatArray(String[] _new) throws Exception 
	{
		if (_new != null)
		{
		float floatarray[] = new float[_new.length];
		for (int i = 0; i < _new.length; i++) {
		floatarray[i] = Float.parseFloat(_new[i]);
		}
		return floatarray;
		}
		return null;
		}
	public void draw(GL10 gl) {
		
		vbb= ByteBuffer.allocateDirect(get_pvertices1().length * 4);
		vbb.order(ByteOrder.nativeOrder());
		_vertexBuffer = vbb.asFloatBuffer();
		_vertexBuffer.clear();
		_vertexBuffer.put(get_pvertices1());
		_vertexBuffer.position(0);
		
		
		ibb = ByteBuffer.allocateDirect(_indices.length * 2);
		ibb.order(ByteOrder.nativeOrder());
		_indexBuffer = ibb.asShortBuffer();
		_indexBuffer.clear();
		_indexBuffer.put(_indices);
		_indexBuffer.position(0);
		
	
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		// Specifies the location and data format of an array of vertex
		// coordinates to use when rendering.
		 // set the color of our element
	    //gl.glColor4f(0.5f, 0.5f, 1.0f, 0.5f);	
	    // define the vertices we want to draw
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer);
        // finally draw the vertices
        gl.glLineWidth(2);
      // gl.glRotatef(45.0f, 1.0f,0.0f,1.0f);
       // gl.glRotatef(45.0f, 0.0f,0.0f,1.0f);
       // gl.glDrawElements(GL10.GL_LINES, _indices.length, GL10.GL_UNSIGNED_SHORT, _indexBuffer);	
        gl.glDrawArrays(GL10.GL_LINES, 0, 24);
		// Disable the vertices buffer.
		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
		
	}
	
}